using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.IO;

namespace EventAbstractionAPI.RuleTableCtrl
{
    public partial class Intellisense : Form
    {
        public event EventHandler List_DoubleClicked;
        public event KeyPressEventHandler List_KeyPressed;

        public Intellisense(int ruleNumber, int column)
        {
            _ruleNumber = ruleNumber;
            _column = column;
            InitializeComponent();
        }

        public int RuleNumber
        {
            get { return _ruleNumber; }
            set { _ruleNumber = value; }
        }

        public int Column
        {
            get { return _column; }
            set { _column = value; }
        }
        
        private void Intellisense_Load(object sender, EventArgs e)
        {
            //
            //tell windows we are interested in drawing items in ListBox on our own
            this.listBox1.DrawItem += new DrawItemEventHandler(this.DrawItemHandler);
            //this.GotFocus += new EventHandler(Intellisense_GotFocus);
        }

        //void Intellisense_GotFocus(object sender, EventArgs e)
        //{
        //    this.LostFocus += new EventHandler(Intellisense_LostFocus);
        //}
        

        //void Intellisense_LostFocus(object sender, EventArgs e)
        //{
        //    this.Dispose();
        //    this.Close();
        //}

        private void DrawItemHandler(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();

            Stream iconStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EventAbstractionAPI.RuleTableCtrl.Resources.Event.ico");
            Icon icon = new Icon(iconStream);

            e.Graphics.DrawIcon(icon, 0, e.Index * 16);
            e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular), new SolidBrush(Color.RoyalBlue), 16, e.Index *16);
        }


        #region Member Variables

        int _ruleNumber;
        int _column;

        #endregion

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            List_DoubleClicked.Invoke(sender, e);
        }

        private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            List_KeyPressed.Invoke(sender, e);
        }
    }
}